<?php
/*
 *   This file is part of poat.
 *
 *   poat is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   poat is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with poat.  If not, see <http://www.gnu.org/licenses/>.
 */
 
require_once(ROOT_PATH."class/project.class.php");

if (($param['op']=='act' or $param['op']=='deact') and $flow_ok) {
	$project = new project;
	$project->id=$param['sid'];
	$ret = $loader->get($project);
	if ($ret) {
		if ($param['op']=='act') {
			$project->status=STATUS_ACTIVE;
		} else {
			$project->status=STATUS_INACTIVE;
		}
		$loader->update($project);
	}
	$message=$LANG['updated'];
} elseif ($param['op']=='add' and $flow_ok) {
	$project = new project;
	$project->name=$param['name'];
	$path = trim($param['path']);
	if (substr($path,0,1)!='/') $path='/'.$path;
	if (substr($path,strlen($path)-1)=='/') $path=substr($path,0,strlen($path)-1);
	$project->path=$path;
	$project->parent=$param['id'];
	$loader->save($project);
} elseif ($param['op']=='edit' and $flow_ok) {
	$project = new project;
	$project->id=$param['sid'];
	$ret = $loader->get($project);
	if ($ret) {
		$project->name=$param['name'];
		$project->path=$param['path'];
		$loader->update($project);
		$message=$LANG['updated'];
	}
}

$project = new project;
$project->id=$param['id'];
$list = $loader->loadListBy($project,$project->listSubProjects());

$tm->assign('id',$param['id']);
$tm->assign('list',$list);
$content = $tm->fetch('sprlist.tpl');

?>
